/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package ims.banking;

import java.util.ArrayList;

public class TaskManager {
    private ArrayList<String> highPriority;
    private ArrayList<String> lowPriority;

    public TaskManager() {
        highPriority = new ArrayList<>();
        lowPriority = new ArrayList<>();
    }

    public void addTask(String task) {
        if (task.contains("*")) {
            highPriority.add(task);
        } else {
            lowPriority.add(task);
        }
    }

    public boolean removeTask(String priority, int index) {
        if (priority.equalsIgnoreCase("high")) {
            if (index >= 0 && index < highPriority.size()) {
                highPriority.remove(index);
                return true;
            }
        } else if (priority.equalsIgnoreCase("low")) {
            if (index >= 0 && index < lowPriority.size()) {
                lowPriority.remove(index);
                return true;
            }
        }
        return false;
    }

    public boolean changePriority(String priority, int index) {
        if (priority.equalsIgnoreCase("high") && index >= 0 && index < highPriority.size()) {
            String task = highPriority.remove(index);
            lowPriority.add(task.replace("*", ""));
            return true;
        } else if (priority.equalsIgnoreCase("low") && index >= 0 && index < lowPriority.size()) {
            String task = lowPriority.remove(index);
            highPriority.add("*" + task);
            return true;
        }
        return false;
    }

    public boolean promoteTask(int index) {
        if (index > 0 && index < highPriority.size()) {
            String task = highPriority.get(index);
            highPriority.set(index, highPriority.get(index - 1));
            highPriority.set(index - 1, task);
            return true;
        }
        return false;
    }

    public ArrayList<String> getHighPriorityTasks() {
        return highPriority;
    }

    public ArrayList<String> getLowPriorityTasks() {
        return lowPriority;
    }
}
